﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace 登录注册功能_sqlserver
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
        /// <summary>
        ///  用户登录界面功能实现
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void LoginInbutton_Click(object sender, EventArgs e)
        {
            // 判空
            string username = UserNametextBox.Text;
            string password = PasswordtextBox.Text;
            if (username == "" || password == "") {
                MessageBox.Show("账号或者密码为空");
                return;
            }
            //获取用户名密码
            UserTModelForEF UserT = new UserTModelForEF();
            using (MyDbContext mydb =new MyDbContext()) {
                UserT = mydb.UserTForWinform.FirstOrDefault(X => X.Username== username && X.Password== password);
            }
            //判断账号密码是否正确
            if (UserT == null)
            {
                MessageBox.Show("你的账号密码不正确");
                return;
            }
            else {
                MessageBox.Show($"欢迎尊敬的用户{UserT.Username}进入");
                index index = new index(UserT);
                index.Show();
                this.Hide();
            }

        }

        private void ZhuceLabel_Click(object sender, EventArgs e)
        {
            RegisterForm RF = new RegisterForm();
            RF.ShowDialog();
        }
    }
}
